package com.ftx.common.util;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;


public class DateUtils {

    /**
     * 一天的秒数
     */
    public static final int ONE_DAY_SECONDS = 86400;
    /**
     * 十天的秒数
     */
    public static final int TEN_DAYS_SECONDS = 864000;

    /**
     * 一天的毫秒数
     */
    public static final long ONE_DAY_MS = 86400000;

    /**
     * 一小时的秒数
     */
    public static final int ONE_HOUR_SECONDS = 3600;

    /**
     * 获取锁的超时时间1秒
     */
    public static final int GET_LOCK_EXPIRE_TIME = 1;

    public static final String YYYYMMDD = "yyyy-MM-dd";
    public static final String YYYYMMDD_HHMMSS = "yyyy-MM-dd HH:mm:ss";

//    /**
//     * 验证是否是"yyyy-MM-dd HH:mm:ss"的格式
//     *
//     * @param date
//     * @returnf
//     */
//    public static boolean isDateFormat(String date) {
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        format.setLenient(false);
//        if (date == null || StringUtils.isBlank(date))
//            return false;
//        try {
//            format.parse(date);
//        } catch (ParseException e) {
//            return false;
//        }
//        return true;
//    }

    public static String getDateBeforeOrAfter(Date currentDate, int segment, String format) throws Exception {
        Calendar c = Calendar.getInstance();
        c.setTime(currentDate);
        c.add(Calendar.MONTH, segment);
        Date d = c.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(d);
    }
    /**
     * 获取输入日期的后一天
     *
     * @param currentDate 输入日期
     * @return 输入日期的前一天
     */
    public static Date getTomorrow(Date currentDate) throws Exception {
        Calendar c = Calendar.getInstance();
        c.setTime(currentDate);
        c.add(Calendar.DATE, 1);
        Date d = c.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat(YYYYMMDD);
        return createDate(sdf.format(d), YYYYMMDD);
    }

    /**
     * 将时间转化为指定格式的字符串
     *
     * @param date   输入日期
     * @param format 日期格式
     * @return 字符串格式的日期
     * @author lishuai
     */
    public static String format(Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
    /**
     * 将字符串转换成date类型
     */
    public static Date stringToDate(String date) throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return sdf.parse(date);
        } catch (ParseException e) {
            throw new Exception(e);
        }
    }

//    /**
//     * 验证时间格式
//     *
//     * @param date   字符串时间格式
//     * @param format
//     * @return
//     */
//    public static boolean checkDateFormat(String date, String format) {
//        SimpleDateFormat sdf = new SimpleDateFormat(format);
//        sdf.setLenient(false);
//        if (date == null || StringUtils.isBlank(date))
//            return false;
//        try {
//            sdf.parse(date);
//        } catch (ParseException e) {
//            return false;
//        }
//        return true;
//    }

    /**
     * 获取现在时间
     *
     * @return 返回字符串格式 yyyy-MM-dd HH:mm:ss
     */
    public static String getStringNowDate() {
        Date currentTime = new Date(System.currentTimeMillis());
        return DateFormatUtils.format(currentTime, "yyyy-MM-dd HH:mm:ss");
    }
    public static Date formatToDate(Date date, String format) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return createDate(sdf.format(date), format);
    }
    /**
     * 将时间格式的字符串，转化为Date
     *
     * @param dateFormat exp: 2010-7-22
     * @return java.util.Date
     */
    public static Date createDate(String dateString, String dateFormat) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        Date d = sdf.parse(dateString);
        return d;
    }

    /**
     * 比较时间，开始时间小于结束时间的返回true，否则返回false
     *
     * @param start
     * @param end
     * @return
     */
    public static boolean compareDate(String start, String end) throws ParseException {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date startDate = format.parse(start);
            Date endDate = format.parse(end);
            if (startDate.before(endDate)) {
                return true;
            } else if (startDate.equals(endDate)) {
                return true;
            }
        } catch (ParseException e) {
            throw e;
        }
        return false;
    }

    /**
     * @param start 开始时间
     * @param end   结束时间
     * @return 比较时间，开始时间小于等于结束时间的返回true，否则返回false
     */
    public static boolean compareDate(Date start, Date end) {
        return start.before(end) || start.equals(end);
    }

    /**
     * 计算两个时间之间的所间隔的月数
     *
     * @param start
     * @param end
     * @param monthSpace 间隔的月数
     * @return start大于end monthSpace个月的返回false，小于的返回true
     */
    public static boolean compareMonthDate(String start, String end, int monthSpace) throws ParseException {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date startDate = format.parse(start);
            Date endDate = format.parse(end);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(startDate);
            calendar.add(Calendar.MONTH, monthSpace);
            if (endDate.getTime() <= calendar.getTime().getTime()) {
                return true;
            }

        } catch (ParseException e) {
            throw e;
        }
        return false;
    }

    /**
     * 计算两个时间之间的所间隔的月数
     *
     * @param start
     * @param end
     * @param monthSpace 间隔的月数
     * @return start大于end monthSpace个月的返回false，小于的返回true
     */
    public static boolean compareMonthDate(Date start, Date end, int monthSpace) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(start);
        calendar.add(Calendar.MONTH, monthSpace);
        return end.getTime() <= calendar.getTime().getTime();
    }

    /**
     * 将2011-03-01 00:00:00
     * 变成：
     * 2010-07-21T16:00:00Z
     *
     * @param time
     * @return
     */
    public static String getSolrTime(String time) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
//        format.setTimeZone(TimeZone.getTimeZone("Z"));
        String date = format2.format(format.parse(time));
        return date;


    }

    /**
     * 返回指定格式的日期
     *
     * @param strDate 字符串日期
     * @param pattern 返回日期样式
     */

    public static Date getDate(String strDate, String pattern) {
        if (strDate == null)
            return null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        try {
            return simpleDateFormat.parse(strDate.trim());
        } catch (ParseException ex) {
            return null;
        }
    }

    /**
     * 提交URL访问时间和服务器接收到请求的时间比较，验证链接是否超时
     * 开始日期小于等于结束日期为True,反之False
     *
     * @param visitTime  服务器获得商家请求的时间
     * @param serverTime 服务器接收日期
     */
    public static boolean compareTimeStamp(Date visitTime, Date serverTime) {
        Calendar visitCalendar = Calendar.getInstance();
        Calendar serverCalendar = Calendar.getInstance();
        visitCalendar.setTime(visitTime);
        serverCalendar.setTime(serverTime);
        int result = serverCalendar.compareTo(visitCalendar);
        if (result == 0 || result == -1)
            return true;
        else
            return false;


    }

    /**
     * 日期相加
     *
     * @param date 日期
     * @interval 设置间隔天数
     * @type Calendar.DATE(1) or Calendar.MONTH(2) or Calendar.YEAR(5)orCalendar.MINUTE(12)
     */

    public static Date addDate(Date date, int interval, int type) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(type, interval);
        return calendar.getTime();
    }

    /**
     * 获取前三个月的日期
     *
     * @return
     */
    public static String getBeforeThreeMonthDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.MONTH, -3);
        return format.format(calendar.getTime());
    }

    /**
     * 获取前三个月的日期
     *
     * @return
     */
    public static String getBeforeOneMonthDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.MONTH, -1);
        return format.format(calendar.getTime());
    }

    public static Date getBeforeSecondDate(int second) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.SECOND, -second);
        return calendar.getTime();
    }

    public static String getToday() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(new Date());
    }

    /**
     * 将date 日期格式化        *
     *
     * @param date
     * @return
     */
    public static String formatDate(Date date) {
        if (date == null) return "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        sdf.setTimeZone(TimeZone.getTimeZone("Z"));
        return sdf.format(date);
    }

    /**
     * 将date 日期格式化  date 是含有时区的时间      *
     *
     * @param date
     * @return
     */
    public static String getFormatDate(Date date) {
        if (date == null) return "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }

    /**
     * 返回指定格式的日期字符串
     *
     * @param date    转换日期
     * @param pattern 日期格式
     */
    public static String getDateString(Date date, String pattern) {
        if (date == null) return "";
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        return formatter.format(date);
    }

    /**
     * 获取相差的描述
     *
     * @param startTime 开始日期
     * @param endDate   结束日期
     * @return
     */
    public static long getSecondsDiffer(Date startTime, Date endDate) {
        long st = startTime.getTime();
        long ed = endDate.getTime();
        return (ed - st) / 1000;
    }

    /**
     * 获取距离当前时间前n天的日期
     *
     * @param n 天
     * @return
     */
    public static Date getLastNDays(int n) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - n);
        return calendar.getTime();
    }

    /**
     * 获取输入日期的前一天
     *
     * @param currentDate 输入日期
     * @return 输入日期的前一天
     */
    public static Date getYesterday(Date currentDate) {
        Calendar c = Calendar.getInstance();
        c.setTime(currentDate);
        c.add(Calendar.DATE, -1);
        return c.getTime();
    }

    /**
     * 获取输入日期的前一周
     *
     * @param currentDate 输入日期
     * @return 输入日期的前一周
     */
    public static Date getLastWeek(Date currentDate) {
        Calendar c = Calendar.getInstance();
        c.setTime(currentDate);
        c.add(Calendar.WEEK_OF_YEAR, -1);
        return c.getTime();
    }

    /**
     * 获取输入日期的前一月
     *
     * @param currentDate 输入日期
     * @return 输入日期的前一月
     */
    public static Date getLastMonth(Date currentDate) {
        Calendar c = Calendar.getInstance();
        c.setTime(currentDate);
        c.add(Calendar.MONTH, -1);
        return c.getTime();
    }

    /**
     * 获取本月第一天
     *
     * @param currentDate
     * @return
     */
    public static Date getFirstDateCurrentMonth(Date currentDate) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());// 设置当前日期
        int day = calendar.getMinimum(Calendar.DAY_OF_MONTH);// 取得当前月的最小日期(天)
        calendar.set(Calendar.DAY_OF_MONTH, day);// 设置天
        return calendar.getTime();
    }

    /**
     * 得到这周的第一天
     *
     * @param dateStr 格式为 yyyyww 如：201522
     * @return yyyy-MM-dd 如：2015-05-25
     * @throws ParseException
     */
    public static String getFirstDateOfWeek(String dateStr) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyww");
        Date date = simpleDateFormat.parse(dateStr);


        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);


        return getDateString(calendar.getTime(), "yyyy-MM-dd");
    }

    /**
     * 得到这周的最后天
     *
     * @param dateStr 格式为 yyyyww 如：201522
     * @return yyyy-MM-dd 如：2015-05-31
     * @throws ParseException
     */
    public static String getLastDateOfWeek(String dateStr) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyww");
        Date date = simpleDateFormat.parse(dateStr);


        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 7);

        return getDateString(calendar.getTime(), "yyyy-MM-dd");
    }

    /**
     * 得到这周的第一天0时 如 2015-05-25 00:00:00
     *
     * @param dateStr 格式为 yyyyww 如：201522
     * @return
     * @throws ParseException
     */
    public static Date getFirstDateZeroTimeOfWeek(String dateStr) {


        try {

            String dayZeroTime = getFirstDateOfWeek(dateStr) + " " + "00:00:00";

            return getDate(dayZeroTime, "yyyy-MM-dd HH:mm:ss");


        } catch (Exception e) {

        }
        return null;


    }

    /**
     * 得到这周的最后一天23:59:59时 如 2015-05-31 23:59:59
     *
     * @param dateStr 格式为 yyyyww 如：201522
     * @return
     * @throws ParseException
     */
    public static Date getLastDateFinalTimeOfWeek(String dateStr) {

        try {

            String dayFinalTime = getLastDateOfWeek(dateStr) + " " + "23:59:59";

            return getDate(dayFinalTime, "yyyy-MM-dd HH:mm:ss");


        } catch (Exception e) {

        }
        return null;

    }

    /**
     * 得到今天0时，2015-05-25 00:00:00
     *
     * @param dateStr 格式为2015-05-25
     * @return
     */
    public static Date getDateZeroTime(String dateStr) {

        dateStr = dateStr + " " + "00:00:00";

        return getDate(dateStr, "yyyyMMdd HH:mm:ss");

    }

    /**
     * 得到今天最后时刻，2015-05-31 23:59:59
     *
     * @param dateStr 格式为2015-05-25
     * @return
     */
    public static Date getDateFinalTime(String dateStr) {

        dateStr = dateStr + " " + "23:59:59";

        return getDate(dateStr, "yyyyMMdd HH:mm:ss");

    }

    /**
     * 根据当前日期返回前几个月的格式化日期
     *
     * @param arg
     * @throws Exception
     */
    public static List getMonthsTime(int arg) {
        Calendar c = Calendar.getInstance();
        c.setFirstDayOfWeek(Calendar.MONDAY);
        c.setTime(new Date());
        int indexCurrentWeek = c.get(Calendar.WEEK_OF_YEAR);

        c.add(Calendar.MONTH, arg);
        int indexPreMonthWeek = c.get(Calendar.WEEK_OF_YEAR);

        c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        Date weekStartDate = c.getTime();

        c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
        Date weekEndDate = c.getTime();

        List resultList = new ArrayList();
        int between = indexCurrentWeek - indexPreMonthWeek;
        for (int i = 0; i < between; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            Date startDate = DateUtils.addDate(weekStartDate, 7 * i, Calendar.DATE);
            Date endDate = DateUtils.addDate(weekEndDate, 7 * i, Calendar.DATE);
            String year = DateFormatUtils.format(startDate, "yyyy");
            map.put("week", year + (indexPreMonthWeek + i + ""));
            map.put("beginDate", DateFormatUtils.format(startDate, "MM-dd"));
            map.put("endDate", DateFormatUtils.format(endDate, "MM-dd"));
            resultList.add(map);
        }
        return resultList;
    }

    /**
     * 获取每个月有多少天
     *
     * @return
     */
    public static int getDayOfMonth(Date date) {
        Calendar aCalendar = Calendar.getInstance();
        aCalendar.setTime(new Date());
        aCalendar.set(Calendar.YEAR, aCalendar.get(Calendar.YEAR));
        aCalendar.set(Calendar.MONTH, aCalendar.get(Calendar.MONTH));//Java月份才0开始算  6代表上一个月7月
        int day = aCalendar.getActualMaximum(Calendar.DATE);
        return day;
    }

    /**
     * 获取当前时刻到今天结束的秒数
     *
     * @return
     */
    public static int getSecondsBetweenNowAndEnd() {
        Calendar now = Calendar.getInstance();
        //今天的结束就是明天的开始
        Calendar end = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE) + 1, 0, 0, 0);
        return (int) ((end.getTimeInMillis() - now.getTimeInMillis()) / 1000);
    }

    /**
     * 获取日期int值 格式yyyyMMdd
     *
     * @return
     */
    public static long getDateIntValue(String pattern) {
        return Long.parseLong(new SimpleDateFormat(pattern).format(new Date()));
    }

    /**
     * @return 当前秒级时间戳
     */
    public static int currentSecondTime() {
        return (int) (System.currentTimeMillis() / 1000);
    }

    /**
     * 获取今日零点的秒级时间戳
     *
     * @return
     */
    public static int currentBeginSecondTime() {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        return (int) (c.getTimeInMillis() / 1000);
    }

    /**
     * 计算两个时间相差天数（精确到秒）
     *
     * @param dateStart 开始时间
     * @param dateEnd   结束时间
     * @return 两个时间相差天数
     */
    public static int getDiscrepantDays(Date dateStart, Date dateEnd) {
        if (null == dateStart || null == dateEnd) {
            return -1;
        }
        long intervalMilli = dateStart.getTime() - dateEnd.getTime();
        return (int) (intervalMilli / (ONE_DAY_SECONDS * 1000));
    }

//    /**
//     * 判断是否日期是否是未来
//     *
//     * @param date yyyy-MM-dd HH:mm:ss
//     * @return true：是，false：不是
//     */
//    public static boolean isFuture(String date) {
//        Date d = stringToDate(date);
//        return d != null && d.getTime() > System.currentTimeMillis();
//    }

    /**
     * 日期加上若干天后的日期
     *
     * @param date 日期
     * @param days 加的天数
     * @return 加后的天数
     */
    public static Date add(Date date, int days) {
        return new Date(date.getTime() + days * ONE_DAY_MS);
    }

    // 验证时间是否在某个日期 开始和结算时间之类
    public static boolean validateDateIsBetween(long date, long before, long after) {
        return date > before && date < after;
    }

    /**
     * 获取当前日期下一年的时间
     *
     * @return
     */
    public static Date nextYear(Date date, int year) {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.add(GregorianCalendar.YEAR, year);// 在年上加year
        return cal.getTime();
    }

    /**
     * 获取某个日期 n个月后的日期
     * @param num 正数:n个月后, 负数:n个月前
     */
    public static Date nextSomeMonthDate(Date date, int num) {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.add(GregorianCalendar.MONTH, num);// 修改月份
        return cal.getTime();
    }

    /**
     * 获取当前日期若干小时后的时间
     *
     * @return
     */
    public static Date nextHour(Date date, int hour) {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.add(GregorianCalendar.HOUR, hour);
        return cal.getTime();
    }

    /**
     * 获取今天的开始时间
     */
    public static Date getTodayBeginDate() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    }

    /**
     * 获取昨天的开始时间
     */
    public static Date getYesterdayBeginDate() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.add(Calendar.DAY_OF_YEAR, -1);
        return calendar.getTime();
    }

    /**
     * 获取昨天的开始时间
     */
    public static Date getTommorrowBeginDate() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        return calendar.getTime();
    }

    /**
     * 计算两个日期之间相差的天数
     *
     * @param startDate 开始的时间
     * @param endDate   结束的时间
     * @return 相差天数
     */
    public static int daysBetween(Date startDate, Date endDate) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            startDate = sdf.parse(sdf.format(startDate));
            endDate = sdf.parse(sdf.format(endDate));

        } catch (ParseException e) {
            throw new Exception(e);
        }
        long between_days = (endDate.getTime() - startDate.getTime()) / (1000 * 3600 * 24);

        return Integer.parseInt(String.valueOf(between_days));
    }

    /**
     * 获取现在时间
     * @return Date
     */
    public static Date getNow(){
        return new Date(System.currentTimeMillis());
    }


    public static Date getBeginOfDateLastMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
//        calendar.add(Calendar.YEAR, 0);
//        calendar.add(Calendar.MONTH, -1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 获取上个月的结束时间
     */
    public static Date getEndOfDateLastMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
//        c.add(Calendar.MONTH, -1);
        c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));// 获取当前月最后一天
        c.set(Calendar.HOUR_OF_DAY, 23);
        c.set(Calendar.MINUTE, 59);
        c.set(Calendar.SECOND, 59);
        c.set(Calendar.MILLISECOND, 999);
        return c.getTime();
    }

    private static void testInteger(Integer integer){
        for (int i = 0;i < 20;i++){
            integer++;
        }
    }

    public static Date convertDate(String date, String pattern) {
        try {
            if (org.apache.commons.lang.StringUtils.isEmpty(pattern) || StringUtils.isEmpty(date)) {
                String msg = "the date or pattern is empty.";
                throw new IllegalArgumentException(msg);
            }
            SimpleDateFormat df = new SimpleDateFormat(pattern.trim());
            return df.parse(date.trim());
        } catch (Exception e) {
            return null;
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            System.out.println(new Date());

        }
    }


}
